package cn.jhc.dao;

import cn.jhc.entity.Book;
import cn.jhc.entity.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface OrderDAO {
    @Insert("insert into t_order(create_time,price,status,user_id) values(#{createTime},#{price},#{status},#{userId})")
    @SelectKey(statement = "select last_insert_id()",keyProperty = "orderId",before = false,resultType = Integer.class)
    public int save(Order order);

    @Update({"<script>",
            "update t_order",
            "  <set>",
            "    <if test='createTime != null'>create_time=#{createTime},</if>",
            "    <if test='price != null'>price=#{price},</if>",
            "    <if test='status != null'>status=#{status},</if>",
            "    <if test='userId != null'>user_id=#{userId},</if>",
            "  </set>",
            "where order_id=#{orderId}",
            "</script>"})
    public int update(Order order);

    @Delete("delete from t_order where order_id=#{orderId}")
    public int delete(Integer orderId);

    @Select("select * from t_order where order_id=#{orderId}")
    public Order queryOne(Integer orderId);

    @Select({"<script>",
            "select * from t_order",
            "  <where>",
            "    <if test='createTime != null'>create_time=#{createTime}</if>",
            "    <if test='price != null'>price=#{price}</if>",
            "    <if test='status != null'>status=#{status}</if>",
            "    <if test='userId != null'>user_id=#{userId}</if>",
            "  </where>",
            "</script>"})
    public List<Order> query(Order order);

    @Select("select * from t_order where user_id=#{userId}")
    public List<Order> QueryByUser(Integer userId);


}
